<?php
class PagosController extends AppController {

	var $name = 'Pagos';
    var $uses = array('Pago','Caja');
	function index() {
		$this->Pago->recursive = 0;
		$this->set('pagos', $this->paginate());
	}
	function procesar($id ,$impu ){
		//echo  $id . " " . $impu;
		$this->set('id', $id);
		$condiciones = array('Pago.contribuyente_id  '=> $id,'Pago.impuesto_id'=>$impu );
        $this->set('ultimoPago', $this->Pago->find('all',array('conditions' => $condiciones)));
        $this->set(compact('ultimoPago'));
	}
    
	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid pago', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('pago', $this->Pago->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Pago->create();
			if ($this->Pago->save($this->data)) {
				$this->Session->setFlash(__('The pago has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The pago could not be saved. Please, try again.', true));
			}
		}
		$contribuyentes = $this->Pago->Contribuyente->find('list');
		$impuestos = $this->Pago->Impuesto->find('list');
		$this->set(compact('contribuyentes', 'impuestos'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid pago', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Pago->save($this->data)) {
				$this->Session->setFlash(__('The pago has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The pago could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Pago->read(null, $id);
		}
		$contribuyentes = $this->Pago->Contribuyente->find('list');
		$impuestos = $this->Pago->Impuesto->find('list');
		$this->set(compact('contribuyentes', 'impuestos'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for pago', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Pago->delete($id)) {
			$this->Session->setFlash(__('Pago deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Pago was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
        function beforeFilter() {
		//$this->Acl->allow($aroAlias, $acoAlias);
   		 parent::beforeFilter();
    		    	
			$this->Auth->allow(array('*'));

    	}
}
?>
